package com.yxh.lib_base.ext.net

import com.yxh.lib_base.network.AppException
import com.yxh.lib_base.network.BaseResponse
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map

/**
 * @author yuanxh
 * @date :2023/6/21 20:16
 * @description:
 */


/**
 * 脱壳
 * */
public inline fun <T, R : BaseResponse<T>> Flow<R>.asPeeling(): Flow<T> = map {
    if (it.isSuccess()) {
        it.getData()
    } else {
        throw AppException(it.getCode(), it.getMsg(), it.getMsg())
    }
}
